<extend name="./public/frame.html"/>
<block name="content">
    <style type="text/css">
        blockquote {
            -webkit-margin-end: 0px;
        }
    </style>
    <blockquote class="layui-elem-quote search">
    <!--<div class="layui-row">-->
        <!--<div class="layui-col-xs12 layui-col-md5 layui-col-lg4">-->
            <!--<div class="layui-form">-->
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <input type="text" class="layui-input date" readonly id="start" placeholder="申请时间-起">
                        </div>
                        <div class="layui-inline">
                            <input type="text" class="layui-input date" readonly id="end" placeholder="申请时间-止">
                        </div>
                    </div>
                </div>
            <!--</div>-->
        <!--</div>-->
        <!--<div class="layui-col-xs12 layui-col-md5 layui-col-lg4">-->
            <!--<div class="layui-row">-->
                <!--<div class="layui-col-xs3">-->
                    <!--<div class="layui-form">-->
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" lay-verify="required|" required placeholder="请输入订单号"  class="layui-input" id="order_sn">
                            </div>
                        </div>
                    <!--</div>-->
                <!--</div>-->
                <!--<div class="layui-col-xs3">-->
                    <!--<div class="layui-form">-->
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" lay-verify="required|number" required placeholder="请输入申请人手机号"  class="layui-input" id="user_phone" maxlength="11" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onblur="value=value.replace(/[^\d]/g,'')">
                            </div>
                        </div>
                    <!--</div>-->
                <!--</div>-->
                <!--<div class="layui-col-xs3">-->
                    <!--<div class="layui-form">-->
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select lay-verify="required" class="layui-input" lay-search="" id="pay_type" style="width: 90px;">
                                    <option value="">付款方式</option>
                                    <volist name="pay_type" id="type">
                                        <option value="{$key}">{$type}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                    <!--</div>-->
                <!--</div>-->
                <!--<div class="layui-col-xs3">-->
                    <!--<div class="layui-form">-->
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select lay-verify="required" class="layui-input" lay-search="" id="is_handle" style="width: 90px;">
                                    <option value="">退款状态</option>
                                    <option value="1">已退款</option>
                                    <option value="2">未退款</option>
                                </select>
                            </div>
                        </div>
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="layui-col-xs12 layui-col-md2 layui-col-lg2">-->
            <div class="layui-btn-group">
                <button class="layui-btn" data-type="search">搜索</button>
                <button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
                <button class="layui-btn layui-btn-warm" data-type="excel" style="margin-left: 20px;">导出</button>
            </div>
        <!--</div>-->
    <!--</div>-->
    </blockquote>
    <table class="layui-table"
           lay-data="{cellMinWidth: 80, height:'auto', url:'{$url}', page: true,limit: 10, id:'refund'}"
           lay-filter="refund">
        <thead>
        <tr>
            <th lay-data="{checkbox:true,fixed: true}"></th>
            <th lay-data="{field:'id', width:80, fixed: true, sort: true}">ID</th>
            <th lay-data="{field:'refund_sn', width:190, sort: true}">退款单号</th>
            <th lay-data="{field:'order_sn', width:190}">订单号</th>
            <th lay-data="{field:'user_phone', width:120}">申请人</th>
            <th lay-data="{field:'refund_time', width:200, sort: true,}">申请时间</th>
            <th lay-data="{field:'refund_money', width:120, sort: true,templet:refundTpl}">申请退款金额</th>
            <th lay-data="{field:'user_money', width:120,templet:moneyTpl}">余额付款</th>
            <th lay-data="{field:'paytool', width:100,}">付款途径</th>
            <th lay-data="{field:'is_handle', width:100,templet:handleTpl}">是否退回</th>
            <th lay-data="{field:'fact_money', width:130, sort: true,templet:factTpl}">实际退款金额	</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:120, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
        <!--{{#if(d.is_handle==2){}}-->
        <!--<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="refund">退款</a>-->
        <!--{{#}else{}}-->
        <!--<a class="layui-btn layui-btn-xs layui-btn-disabled">退款</a>-->
        <!--{{#}}}-->
    </script>
    <script type="text/html" id="refundTpl">
        ￥{{d.refund_money}}
    </script>
    <script type="text/html" id="moneyTpl">
        ￥{{d.user_money}}
    </script>
    <script type="text/html" id="handleTpl">
        {{#if(d.is_handle==1){}}
        已退款
        {{#}else{}}
        未处理
        {{#}}}
    </script>
    <script type="text/html" id="factTpl">
        {{#if(d.fact_money){}}
        ￥{{d.fact_money}}
        {{#}}}
    </script>
    <script type="application/javascript">
        layui.use(['table', 'laytpl', 'laydate','form'], function () {
            var table = layui.table
                , form = layui.form
                , laydate = layui.laydate;
            lay('.date').each(function(){
                laydate.render({
                    elem: this
                    ,type: 'date'
                    ,trigger: 'click'
                });
            });

            //监听工具条
            table.on('tool(refund)', function (obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var id = data.id;
                if (layEvent === 'detail') {
                    layer.open({
                        type: 2,
                        title: '退款申请'+data.refund_sn+',订单号:'+data.order_sn+'的信息',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/inter_refund/detail","id=")}' + id, //iframe的url
                    });
                }
                else if (layEvent === 'refund') {
                    /*$.post('/admin/inter_refund/refund',{id:id},function (res) {
                        switch (res['status']){
                            case 1:
                                layer.alert(res['msg'],{icon: 5},function () {
                                    table.reload('refund', "{$url}");
                                });
                                break;
                            default:
                                layer.alert(res['msg'],{icon: 5});
                                break;
                        }
                    },'json');*/
                    layer.open({
                        type: 2,
                        title: '处理订单号'+data.order_sn+'的退款申请',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/inter_refund/detail","id=")}' + id+'&type=refund', //iframe的url
                        cancel:function (index, layero) {
                            table.reload('refund', "{$url}");
                        }
                    });
                }
            });

            var $ = layui.jquery, active = {
                search: function () {
                    var start = $('#start').val();
                    var end = $('#end').val();
                    var user_phone = $.trim($('#user_phone').val());
                    var order_sn = $.trim($('#order_sn').val());
                    var pay_type = $('#pay_type').val();
                    var is_handle = $('#is_handle').val();
                    var reset = $('#reset');
                    if(start||end||order_sn||user_phone||pay_type||is_handle){
                        reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                        table.reload('refund', {
                            url: '/admin/inter_refund/search',
                            where: {
                                start : start,
                                end : end,
                                order_sn : order_sn,
                                user_phone : user_phone,
                                pay_type : pay_type,
                                is_handle : is_handle
                            } //设定异步数据接口的额外参数
                        });
                    }else{
                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                        layer.alert('搜索项不能为空');
                    }
                }
                , excel: function () {
                    var start = $('#start').val();
                    var end = $('#end').val();
                    var user_phone = $.trim($('#user_phone').val());
                    var order_sn = $.trim($('#order_sn').val());
                    var paytool = $('#pay_type').val();
                    var is_handle = $('#is_handle').val();
                    var str = "&start="+start+"&end="+end+"&user_phone="+user_phone+"&order_sn="+order_sn+"&paytool="+paytool+"&is_handle="+is_handle;
                    layer.confirm('确认导出数据信息:', {
                        btn: ['确认导出', '取消'] //可以无限个按钮
                        , btn3: function (index, layero) {
                            layer.close(index);
                        }
                    }, function (index, layero) {
                        //按钮【按钮一】的回调
                        location = "{:url('excel','all=1')}" + str ;
                        layer.close(index);
                    });
                }
                , reset: function () {
                    var reset = $('#reset');
                    if (reset.data('type') !== '') {
                        table.reload('refund', {
                            url: '/admin/inter_refund/table',where:{}
                        });
                    }
                    $('.layui-input').each(function () {                        $(this).val('');                    });                $('.layui-this').each(function () {$(this).removeClass('layui-this');});
                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                }
            };
            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });

    </script>
</block>
